/*
 * @Author: your name
 * @Date: 2022-02-17 16:16:39
 * @LastEditTime: 2022-02-17 17:09:47
 * @LastEditors: Please set LastEditors
 * @Description: 异步action
 * @FilePath: \geek-app\src\store\action\channel.js
 */
import { getChannelsAPI } from 'api/channel';
import { CHANNEL_SAVE_LIST, CHANNEL_SAVE_CURRENT } from './actionType';

//   1. 封装异步Action
export const getChannelsAction = () => {
  // 💥 返回一个异步函数
  return async (dispatch) => {
    const res = await getChannelsAPI();
    console.log('res', res);
    // 3. 触发同步Action
    dispatch({
      type: CHANNEL_SAVE_LIST,
      payload: res.data.channels,
    });
  };
};

// 封装更新current的同步Action函授
export const saveCurrentAction = (id) => {
  return {
    type: CHANNEL_SAVE_CURRENT,
    payload: id,
  };
};
